package runze.util.base;

/**
 * 向页面传送数据用的response
 * @author wrzhxy@qq.com
 * @创建时间 2017年5月30日 下午5:55:44
 */
public class Response {
	private static final String OK = "ok";
	private static final String ERROR = "error";
	
//	private int status = 200;
	private Msg msg;
	private Object data;
	private Query query;
	
	public Response() {
		msg = new Msg(true, OK, 200);
	}
	public Response success() {
		this.msg = new Msg(true, OK, 200);
		return this;
	}
	public Response success(Object data) {
		this.msg = new Msg(true, OK, 200);
		this.data = data;
		
		return this;
	}
	public Response success(Object data, Query query) {
		this.msg = new Msg(true, OK);
		this.data = data;
		this.query = query;
		return this;
	}
	public Response failure() {
        this.msg = new Msg(false, ERROR, 403);
        return this;
    }

    public Response failure(String message) {
        this.msg = new Msg(false, message, 403);
        return this;
    }
	
	public Msg getMsg() {
		return msg;
	}
	public void setMsg(Msg msg) {
		this.msg = msg;
	}
	public Object getData() {
		return data;
	}
	public void setData(Object data) {
		this.data = data;
	}
	public Query getQuery() {
		return query;
	}
	public void setQuery(Query query) {
		this.query = query;
	}

	public class Msg {
		private boolean success;	//  json js获取到是success
		private String msg;
		private int status;
		public Msg(boolean success) {
            this.success = success;
        }
		public Msg(int status) {
			this.status = status;
		}
		public Msg(boolean success, String msg) {
			this.success = success;
			this.msg = msg;
		}
		public Msg(boolean success, String msg, int status) {
			this.success = success;
			this.msg = msg;
			this.status = status;
		}
		public boolean isSuccess() {
			return success;
		}
		public void setSuccess(boolean success) {
			this.success = success;
		}
		public String getMsg() {
			return msg;
		}
		public void setMsg(String msg) {
			this.msg = msg;
		}
		public int getStatus() {
			return status;
		}
		public void setStatus(int status) {
			this.status = status;
		}
	}
}
